﻿Imports Actuariat
Imports Actuariat.comptes

Public Class PTIC_vueIndicateurs

    Protected _compteTresorerie As compteTresorerie_V2
    Protected _indicateurs As indicateurs_V2

#Region "Propriétés"
    Public Property compteTresorerie() As compteTresorerie_V2
        Get
            Return _compteTresorerie
        End Get
        Set(ByVal value As compteTresorerie_V2)
            _compteTresorerie = value
            refreshValeursCompteTreso()
        End Set
    End Property
    Public Property indicateurs() As indicateurs_V2
        Get
            Return _indicateurs
        End Get
        Set(ByVal value As indicateurs_V2)
            _indicateurs = value
            refreshValeursIndicateurs()
        End Set
    End Property
#End Region

#Region "Initialisation"
    Protected Overrides Sub initNbLignes()
        If Me.ColumnCount = 0 Then
            Me.ColumnCount = 1
        End If
        For i As Integer = 1 To 30
            Me.Rows.Add()
            Me.Rows(i - 1).Height = 15
        Next
        'Cas particuliers
        Rows(3).Height = 6
        Rows(9).Height = 6
        Rows(14).Height = 6
    End Sub
    Protected Overrides Sub initTitresBlocs()
        initLignesBlocCompteTresorerie()
        initLignesBlocROE()
        initLignesBlocSP()
    End Sub
    Protected Overrides Sub initLignesTitresGeneraux()
        Me.Rows(0).Cells(0).Value = ""
    End Sub
    Private Sub initLignesBlocCompteTresorerie()
        'Titre du compte de résultat
        Me.Rows(2).Cells(0).Value = "COMPTE DE TRESORERIE"
        'Titre du compte de trésorerie
        Me.Rows(4).Cells(0).Value = "Variation des capitaux sociaux dûrs "
        Me.Rows(5).Cells(0).Value = "Résultat distribué (perte si nég.)"
        Me.Rows(6).Cells(0).Value = "Flux actionnaire"
    End Sub
    Private Sub initLignesBlocROE()
        'Titre du compte de résultat
        Me.Rows(8).Cells(0).Value = "ROE"
        'Titre du compte de trésorerie
        Me.Rows(10).Cells(0).Value = "Résultat net / Fds Propres Ouv."
        Me.Rows(11).Cells(0).Value = "Résultat net / Capitaux Alloués"
    End Sub
    Private Sub initLignesBlocSP()
        Me.Rows(13).Cells(0).Value = "S/P"
        'Titre du compte de trésorerie
        Me.Rows(15).Cells(0).Value = "DC - (Sinistres réglés / Primes Techniques)"
        Me.Rows(16).Cells(0).Value = "INC/INV - (Sinistres réglés / Primes Techniques)"
        Me.Rows(17).Cells(0).Value = "TOTAL - (Sinistres réglés / Primes Techniques)"
    End Sub
#End Region

#Region "Méthodes de dessin"

    Protected Overrides Sub paintBlocs(ByVal e As System.Windows.Forms.DataGridViewCellPaintingEventArgs)
        'Compte de trésorerie
        paintBloc(e, 2, 6)
        'Bloc ROE
        paintBloc(e, 8, 11)
        'Bloc S/P
        paintBloc(e, 13, 17)
    End Sub

    Protected Overrides Function cellFormat(ByVal rowIndex As String, ByVal columnIndex As String) As String
        If columnIndex <> 0 Then
            If rowIndex = 10 Or rowIndex = 11 Or rowIndex = 15 Or rowIndex = 16 Or rowIndex = 17 Then
                Return _formatDefaut & "%"
            ElseIf rowIndex <> 0 Then
                Return _formatDefaut
            Else
                Return ""
            End If
        Else
            Return ""
        End If
    End Function
    Protected Overrides Function cellBackColor(ByVal rowIndex As String, _
                                   ByVal columnIndex As String, _
                                   ByVal ligneHautBloc As Integer, _
                                   ByVal ligneBasBloc As Integer) As System.Drawing.Color
        If rowIndex = ligneHautBloc Then
            Return Color.FromArgb(231, 213, 231)
        ElseIf rowIndex = 6 Or rowIndex = 17 Then
            Return Color.FromArgb(255, 230, 30)
        Else
            Return Color.White
        End If
    End Function
    Protected Overrides Function cellAlignment(ByVal rowIndex As Integer, ByVal columnIndex As Integer) As StringAlignment
        If columnIndex = 0 Then Return StringAlignment.Near Else Return StringAlignment.Far
    End Function
    Protected Overrides Function cellFont(ByVal rowIndex As Integer, ByVal columnIndex As Integer, ByVal ligneHautBloc As Integer, ByVal ligneBasBloc As Integer) As Font
        If rowIndex = ligneHautBloc Or rowIndex = 6 _
            Or ((rowIndex = 10 Or rowIndex = 11) And columnIndex <> 0) _
            Or rowIndex = 17 Then
            Return New System.Drawing.Font("Tahoma", 9, FontStyle.Bold)
        Else
            Return New System.Drawing.Font("Tahoma", 9, FontStyle.Regular)
        End If
    End Function

#End Region

#Region "Rafraichissements"
    Public Overrides Function actualise(ByVal sender As Object, ByVal notification As Object) As PTIC_Util.resultatValidationContraintes
        'Actualisation des primes
        If TypeOf sender Is compteTresorerie_V2 Then
            refreshValeursCompteTreso()
        ElseIf TypeOf sender Is indicateurs_V2 Then
            refreshValeursIndicateurs()
        ElseIf TypeOf sender Is ComptesMoteur2 Then
            'Actualiser depuis un changement de structure des comptes restitués
            actualiseFromComptesDeclines(sender, notification)
        End If
        Return Nothing
    End Function
    ''Protected Overrides Sub refreshOssature()
    ''  MyBase.refreshOssature()
    'Mise à jour des formats spécifiques des indicateurs
    ''For i As Integer = 1 To _nbAnneesProjection - 1
    ''  Me.Rows(10).Cells(i).Style.Format = _formatDefaut & "%"
    ''Me.Rows(11).Cells(i).Style.Format = _formatDefaut & "%"
    ''Me.Rows(15).Cells(i).Style.Format = _formatDefaut & "%"
    ''Me.Rows(16).Cells(i).Style.Format = _formatDefaut & "%"
    ''Me.Rows(17).Cells(i).Style.Format = _formatDefaut & "%"
    ''Next
    ''End Sub
    Protected Overrides Sub refreshValeursBlocs()
        refreshValeursCompteTreso()
        refreshValeursIndicateurs()
    End Sub
    Protected Overrides Sub refreshTitresGeneraux()
        'Années de projection
        For j As Integer = 1 To _nbAnneesProjection
            Me.Rows(0).Cells(j).Value = CStr(j) - 1 + _anneeDepart
        Next
    End Sub
    Protected Sub refreshValeursCompteTreso()
        If Not compteTresorerie Is Nothing Then
            If compteTresorerie.etatCalcul <> PTIC_Util.valueEtatCalcul.NON_INITIALISE Then
                Me.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None
                With compteTresorerie.resultats
                    For i As Integer = 1 To _nbAnneesProjection
                        If Not .variationCapiSocial Is Nothing Then Me.Rows(4).Cells(i).Value = -.variationCapiSocial(i - 1) / unite
                        If Not .resultatDistribue Is Nothing Then Me.Rows(5).Cells(i).Value = .resultatDistribue(i - 1) / unite
                        If Not .fluxActionnaire Is Nothing Then Me.Rows(6).Cells(i).Value = .fluxActionnaire(i - 1) / unite
                    Next
                End With
                Me.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells
            End If
        End If
    End Sub
    Public Sub refreshValeursIndicateurs()
        If Not indicateurs Is Nothing Then
            If indicateurs.etatCalcul <> PTIC_Util.valueEtatCalcul.NON_INITIALISE Then
                Me.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None
                With indicateurs.resultats
                    For i As Integer = 1 To _nbAnneesProjection - 1
                        If Not .ROE_resNetsFdsPropres Is Nothing Then Me.Rows(10).Cells(i).Value = .ROE_resNetsFdsPropres(i - 1)
                        If Not .ROE_resNetsCapiAlloues Is Nothing Then Me.Rows(11).Cells(i).Value = .ROE_resNetsCapiAlloues(i - 1)
                        If Not .SP_techDC Is Nothing Then Me.Rows(15).Cells(i).Value = .SP_techDC(i - 1)
                        If Not .SP_techINCINV Is Nothing Then Me.Rows(16).Cells(i).Value = .SP_techINCINV(i - 1)
                        If Not .SP_techTot Is Nothing Then Me.Rows(17).Cells(i).Value = .SP_techTot(i - 1)
                    Next
                End With
                Me.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells
            End If
        End If
    End Sub
#End Region

End Class
